package com.toutiao

import java.io.File
import com.typesafe.config._

import com.toutiao.issue.EventStore

import org.apache.log4j.Logger
import org.apache.log4j.PropertyConfigurator

import com.toutiao.issue.IssueProcess

import com.toutiao.time.TimeIssueProcess

class AppProp(
    val mem:Map[String,String]){
  
  def apply(key:String) = mem(key)
  
}

object ReesApp extends App {

  val cc = Array(
    "ES_NAME",
    "ES_URI",
    "ES_PORT",
    "ES_INDEX",
    "ES_TYPE",

    "ES_CONTEXT_NAME",
    "ES_CONTEXT_URI",
    "ES_CONTEXT_PORT",
    "ES_CONTEXT_INDEX",
    "ES_CONTEXT_TYPE",

    "ES_MAP_NAME",
    "ES_MAP_URI",
    "ES_MAP_PORT",
    "ES_MAP_INDEX",
    "ES_MAP_TYPE",

    "TOP_S",
    "MIN_COUNT",
    
    "TIME_LOCATION",
    "TIME_SIZE",
    "TIME_STEP",

    "ES_DOC_NAME",
    "ES_DOC_URI",
    "ES_DOC_PORT",
    "ES_DOC_INDEX",
    "ES_DOC_TYPE",

    "ES_ISSUE_NAME",
    "ES_ISSUE_URI",
    "ES_ISSUE_PORT",
    "ES_ISSUE_INDEX",
    "ES_ISSUE_TYPE",

    "DB_ROOT",
    "DB_CACHE",
    
    "LOCATION_VU",
    "LOCATION_DOC_DATA",

    "MIN_V",
    "MIN_S",
    "MODE"
    
    )
      
  
  PropertyConfigurator.configure("log4j.properties")
  val _log = Logger.getLogger(this.getClass)
  
  println("Hello Rees")
  
  val c = ConfigFactory.parseFile(new File("SimEvent.properties"))
  def initAppProp = {
    val m = cc.map(v => {
      (v,c.getString(v))
    }).toMap
    new AppProp(m)
  }
  
  val prop = initAppProp
  
  val m = prop("MODE").toInt

  if (m == 1) {

    IssueProcess.run(prop)
  }
  
  if (m == 2){

    TimeIssueProcess.run(prop)
  }
  
}

